package com.ruoyi.project.system.uflo.handler;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bstek.uflo.env.Context;
import com.bstek.uflo.model.ProcessInstance;
import com.bstek.uflo.process.assign.AssigneeProvider;
import com.bstek.uflo.process.assign.Entity;
import com.bstek.uflo.process.assign.PageQuery;
import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.system.user.service.IUserService;

/**
 * 系统返回所有人员
 * @author xianz
 *
 */
@Component
public class AllAssigneeProviderHandler implements AssigneeProvider{

	
	@Autowired
	IUserService userService;
	
	@Override
	public boolean isTree() {
		return false;
	}

	@Override
	public String getName() {
		return "所有用户";
	}

	@Override
	public void queryEntities(PageQuery<Entity> pageQuery, String parentId) {
		int index = pageQuery.getPageIndex();
        int size = pageQuery.getPageSize();
        
        Page<User> page = new Page<User>();
        page.setSize(size);
        page.setCurrent(index);
        
        Page<User> pdata = userService.page(page);
        List<User> records = pdata.getRecords();
        List<Entity> entitys = new ArrayList<Entity>();
        for (User user : records) {
        	 entitys.add(new Entity(user.getLoginName(), user.getUserName()));
		}
        pageQuery.setResult(entitys);
        pageQuery.setRecordCount((int) pdata.getTotal());
	}

	@Override
	public Collection<String> getUsers(String entityId, Context context, ProcessInstance processInstance) {
		User user = userService.selectUserByLoginName(entityId);
		List<String> list = new ArrayList<String>();
		list.add(entityId);
		return list;
	}

	@Override
	public boolean disable() {
		// TODO Auto-generated method stub
		return false;
	}

}
